home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / TupleDatabase / BTreeTupleDatabase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  3.9 KB  |  147 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        BTreeTupleDatabase.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __BTREETUPLEDATABASE__
  15. #define __BTREETUPLEDATABASE__
  16.  
  17. #ifndef __TUPLEDATABASE__
  18. #include "TupleDatabase.h"
  19. #endif
  20.  
  21. #ifndef __BTEQU__
  22. #include "BTEqu.h"
  23. #endif
  24.  
  25. #ifndef    __FILESPEC__
  26. #include "FileSpec.h"
  27. #endif
  28.  
  29. #ifndef    __DIRECTOBJECT__
  30. #include "DirectObject.h"
  31. #endif
  32.  
  33. /***********************************|****************************************/
  34.  
  35.  
  36. typedef short (*BTreeCompareProc) ( /* const void* searchInA0, const void* trial */ );
  37.  
  38. class AKeyDescriptor : public TDirectObject
  39. {
  40. public:
  41.  
  42.     static const AKeyDescriptor&    kString;
  43.     static const AKeyDescriptor&    kCompareProc;
  44.  
  45.     virtual    ~AKeyDescriptor ();
  46.  
  47.     virtual    const unsigned char*    GetBtreeDescriptor () const = 0;// subclasses must override
  48.     virtual    unsigned long            GetMaxKeyLength () const;        // returns MaxKeyLen
  49.     virtual    const BTreeCompareProc    GetCompareProc () const;        // returns nil
  50.  
  51.     virtual    ostream&                operator >> ( ostream& ) const;
  52.     virtual    void                    PrintDescriptor ( ostream&, const unsigned char* ) const;
  53.  
  54. protected:    AKeyDescriptor ();
  55. };
  56.  
  57. /***********************************|****************************************/
  58.  
  59. class TBTreeKeyWrapper;
  60.  
  61. class TBTreeDatabase : public ATupleDatabase
  62. {
  63. public:
  64.  
  65.     enum Mode { kReadOnly, kReadWriteNew, kReadWriteOld };
  66.     enum Rights { kNonExclusive, kExclusive };
  67.  
  68.             TBTreeDatabase ( const TFileSpec&, const AKeyDescriptor&, Mode = kReadWriteOld, Rights = kNonExclusive );
  69.     virtual ~TBTreeDatabase ();
  70.  
  71.     virtual Boolean                 SetTuple ( const ATupleKey&, const ADataItem& );
  72.     virtual Boolean                 SetTuple ( unsigned long index, const ADataItem& );
  73.  
  74.     virtual Boolean                 GetTuple ( unsigned long index, ATupleKey&, ADataItem& );
  75.     virtual Boolean                 GetTupleData ( const ATupleKey&, ADataItem& );
  76.     virtual Boolean                 GetTupleData ( unsigned long index, ADataItem& );
  77.     virtual Boolean                 GetTupleKey ( unsigned long index, ATupleKey& );
  78.     virtual Boolean                 GetTupleDataSize ( const ATupleKey&, unsigned long& );
  79.  
  80.     virtual Boolean                 DeleteTuple ( const ATupleKey& );
  81.  
  82.     virtual    CTupleKey*                CreateKey ( unsigned long index );
  83.     virtual Boolean                 FindIndexOfTuple ( const ATupleKey&, unsigned long& index ) const;
  84.     virtual Boolean                 DoesTupleExist ( const ATupleKey& ) const;
  85.     virtual unsigned long             CountTuples () const;
  86.  
  87.     virtual void                     Flush ();
  88.     virtual Boolean                 DeleteDatabase ();
  89.  
  90.     virtual    Boolean                    ReserveAccess ();
  91.     virtual    Boolean                    ReleaseAccess ();
  92.  
  93. // error handling and debugging
  94.  
  95.     virtual    ostream&                operator >> ( ostream& ) const;
  96.             OSErr                    GetError () const;
  97.     virtual    Boolean                    HandleError ( OSErr ) const;
  98.     static    const char*                GetErrorName ( OSErr );
  99.  
  100. protected:    unsigned long            GetTupleDataSize ( const TBTreeKeyWrapper& );
  101.     virtual    Boolean                    GetInfo ( BTParam& ) const;
  102.     virtual    void                    InvalidateHint ();
  103.     static    short                    ComparisonProc ();
  104.  
  105. private:    TBTreeDatabase ( const TBTreeDatabase& );
  106.             TBTreeDatabase&            operator = ( const TBTreeDatabase& );
  107.  
  108.             TFileSpec                fFile;
  109.             OSErr                    fError;
  110.             Rights                    fRights;
  111.             BTIOParam                fParam;
  112. };
  113.  
  114. /***********************************|****************************************/
  115. /***********************************|****************************************/
  116.  
  117. #pragma push
  118. #pragma segment BtreeDatabase
  119.  
  120. inline
  121. AKeyDescriptor::AKeyDescriptor ()
  122. {
  123. }
  124.  
  125. /***********************************|****************************************/
  126.  
  127. inline
  128. AKeyDescriptor::~AKeyDescriptor ()
  129. {
  130. }
  131.  
  132. /***********************************|****************************************/
  133.  
  134. inline unsigned long
  135. AKeyDescriptor::GetMaxKeyLength () const
  136. {
  137.     return MaxKeyLen - 10;
  138. }
  139.  
  140. /***********************************|****************************************/
  141. /***********************************|****************************************/
  142.  
  143. #pragma pop
  144.  
  145. #endif    // __BTREETUPLEDATABASE__
  146.  
  147.